package ie.dkit.semanticPhotoWeb.server.persistence.storageObjects;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * @author Sebastian Ruehl
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */

@Entity
@Table(name = "persons")
@NamedQueries( { @NamedQuery(name = "findPersonByUsername", query = "from Person p where p.username = ?") })
public class Person {
	@Id
	@GeneratedValue
	private int id;

	/*
	 * The username should act in the system as identifier
	 */
	@Basic
	@Column(unique = true)
	private String username;

	@Basic
	private String name;

	@Basic
	private String email;

	@Basic
	private String homepage;

	@Basic
	private String nick;

	@Basic
	private String photo;

	@OneToMany(fetch = FetchType.EAGER)
	private Set<Interest> interests = new HashSet<Interest>();

	@ManyToMany(fetch = FetchType.EAGER)
	private Set<Person> knows = new HashSet<Person>();

	/**
	 * Creates a Person
	 * 
	 */
	public Person() {

	}

	/**
	 * @param id
	 * @param username
	 * @param name
	 * @param email
	 * @param homepage
	 * @param nick
	 * @param photo
	 * @param interest
	 * @param knows
	 */
	public Person(int id, String username, String name, String email,
			String homepage, String nick, String photo,
			Set<Interest> interests, Set<Person> knows) {
		super();
		this.id = id;
		this.username = username;
		this.name = name;
		this.email = email;
		this.homepage = homepage;
		this.nick = nick;
		this.photo = photo;
		this.interests = interests;
		this.knows = knows;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email
	 *            the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the homepage
	 */
	public String getHomepage() {
		return homepage;
	}

	/**
	 * @param homepage
	 *            the homepage to set
	 */
	public void setHomepage(String homepage) {
		this.homepage = homepage;
	}

	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * @return the interests
	 */
	public Set<Interest> getInterests() {
		return interests;
	}

	/**
	 * @param interests
	 *            the interest to set
	 */
	public void setInterests(Set<Interest> interests) {
		this.interests = interests;
	}

	/**
	 * @return the knows
	 */
	public Set<Person> getKnows() {
		return knows;
	}

	/**
	 * @param knows
	 *            the knows to set
	 */
	public void setKnows(Set<Person> knows) {
		this.knows = knows;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the nick
	 */
	public String getNick() {
		return nick;
	}

	/**
	 * @param nick
	 *            the nick to set
	 */
	public void setNick(String nick) {
		this.nick = nick;
	}

	/**
	 * @return the photo
	 */
	public String getPhoto() {
		return photo;
	}

	/**
	 * @param photo
	 *            the photo to set
	 */
	public void setPhoto(String photo) {
		this.photo = photo;
	}

	/**
	 * @return the username
	 */
	public String getUsername() {
		return username;
	}

	/**
	 * @param username
	 *            the username to set
	 */
	public void setUsername(String username) {
		this.username = username;
	}

	/**
	 * Add a Person to known List
	 * 
	 * @param person
	 */
	public void addKnownPerson(Person person) {
		knows.add(person);
	}

	/**
	 * Remove known Person from List
	 * 
	 * @parma person
	 */
	public void removeKnownPerson(Person person) {
		knows.remove(person);
	}

	/**
	 * Add a interest for this Person
	 * 
	 * @param interest
	 */
	public void addInterest(Interest interest) {
		interests.add(interest);
	}

	/**
	 * Remove a interest for this Person
	 * 
	 * @param interest
	 */
	public void removeInterest(Interest interest) {
		interests.remove(interest);
	}
}
